package com.duobaoyu.dby.supply.biz.client.resource.impl;

import com.duobaoyu.dby.common.core.constant.SecurityConstants;
import com.duobaoyu.dby.common.core.constant.ServiceNameConstants;
import com.duobaoyu.dby.common.core.constant.StringPool;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.resource.admin.feign.RemoteResourceChannelSettingConfigAdminService;
import com.duobaoyu.dby.resource.common.admin.dto.config.ChannelSettingConfigDTO;
import com.duobaoyu.dby.resource.common.admin.to.config.ChannelSettingConfigTO;
import com.duobaoyu.dby.resource.common.admin.to.config.ChannelSettingDetailConfigTO;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceChannelSettingConfigAdminClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.ChannelSetConfigDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.ChannelSettingConfigVO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.ChannelSettingDetailConfigVO;
import com.duobaoyu.dby.supply.biz.client.resource.converter.ResourceConverter;
import com.duobaoyu.dby.supply.biz.util.RemoteResultCheckUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName ResourceChannelSettingConfigAdminClientImpl
 * @createTime 14:08:00 2023/10/08
 */
@Component
@RequiredArgsConstructor
public class ResourceChannelSettingConfigAdminClientImpl implements ResourceChannelSettingConfigAdminClient {

    private final ResourceConverter resourceConverter;
    private final RemoteResourceChannelSettingConfigAdminService remoteResourceChannelSettingConfigAdminService;


    @Override
    public List<ChannelSettingConfigVO> channelSettingConfigList() {
        R<List<ChannelSettingConfigTO>> result = remoteResourceChannelSettingConfigAdminService.channelSettingConfingList(SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, StringPool.EMPTY);
        return resourceConverter.toChannelSettingConfigList(result.getData());
    }

    @Override
    public boolean configTopping(String channelCode) {
        R<Boolean> result = remoteResourceChannelSettingConfigAdminService.configTopping(channelCode, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, channelCode);
        return result.getData();
    }

    @Override
    public ChannelSettingDetailConfigVO configDetailById(Long configId) {
        R<ChannelSettingDetailConfigTO> result = remoteResourceChannelSettingConfigAdminService.configDetail(configId, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, configId);
        return resourceConverter.toChannelSettingDetailConfig(result.getData());
    }

    @Override
    public boolean updateConfig(ChannelSetConfigDTO channelSetConfig) {
        ChannelSettingConfigDTO dto = resourceConverter.toChannelSettingConfig(channelSetConfig);
        R<Boolean> result = remoteResourceChannelSettingConfigAdminService.updateConfig(dto, SecurityConstants.FROM_IN);
        RemoteResultCheckUtil.checkRemoteResult(result, ServiceNameConstants.RESOURCE_SERVICE, channelSetConfig);
        return result.getData();
    }
}
